|
In computer science, dynamic dispatch〔Dynamic Dispatch in Object Oriented Languages http://condor.depaul.edu/ichu/csc447/notes/wk10/Dynamic2.htm〕 is the process of selecting which implementation of a polymorphic operation (method or function) to call at run time. Dynamic dispatch contrasts with static dispatch in which the implementation of a polymorphic operation is selected at compile-time. The purpose of dynamic dispatch is to support cases where the appropriate implementation of a polymorphic operation can't be determined at compile time because it depends on the runtime type of one or more actual parameters to the operation. Dynamic dispatch is different from late binding (also known as dynamic binding). In the context of selecting an operation, binding associates a name to an operation. Dispatching chooses an implementation for the operation after you have decided which operation a name refers to. With dynamic dispatch, the name may be bound to a polymorphic operation at compile time, but the implementation not be chosen until run time. However, late binding does imply dynamic dispatching since the binding is what determines the set of available dispatches. Dynamic dispatch is often used in object-oriented languages when different classes contain different implementations of the same method due to common inheritance. For example, suppose you have classes A, B, and C, where B and C both inherit the method foo() from A. Now suppose x is a variable of class A. At run time, x may actually have a value of type B or C and in general you can't know what it is at compile time. With static dispatch, a method call x.foo() will always refer to the implementation of foo() for class A because static binding only looks at the declared type of the object. With dynamic dispatch the language will determine the type of the value of x at run-time and call the version of foo() that is associated with whatever type the value has, whether A, B, or C. ==Single and multiple dispatch== (詳細はtype of the instance. Single dispatch is supported by many object-oriented languages, including statically typed languages such as C++ and Java, and dynamically typed languages such as Smalltalk, Objective-C, JavaScript, and Python. In some languages, such as Common Lisp or Dylan, methods or functions can also be dispatched based on the types of their arguments. Expressed in pseudocode, the code manager.handle(y) could call different implementations depending on the types of both objects manager ''and'' y. This is known as multiple dispatch. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「dynamic dispatch」の詳細全文を読む スポンサード リンク
|